var chartID;

function renderInformation(){
	$('#original_author').text( remoteChartData.chart.firstName + " " + remoteChartData.chart.lastName );
	
	$('#group_name').text( remoteChartData.chart.groupName );
	
	$('#book_name').text( remoteChartData.chart.bookName );

	var qs = window.location.search;
	// Get the id from the request URL
	var id = qs.match(/\?.*?id=(\w+)/);
	id = id[1];	
	
	chartID = id;

	// Bind the edit button.
	$('#PBEdit_Chart').bind('click', function(){
		// If this is the user's chart then this is fine, just send them to the builder.
		// If this isnt the user's chart, or in a group that the user manages, we need to ask if they want to duplicate it (as they cannot edit it).
		window.location = "builder?id=" + chartID;
	});	
	
	$('#PBPrint_Chart').bind('click', function(){
		if(typeof showPrintDialog != "undefined"){
			showPrintDialog(chartID);
		} else {
			window.location = "print?id=" + chartID;
		}
	});
	
	$('#PBDuplicate_Chart').bind('click', function(){
		getFragment("duplicateChart", function(data){
			jQuery.facebox(data);
			$('#chartName').val($('#PBchartNameHolder').text());
			
			// Bind the save button
			$('#confirm_duplicate_chart').bind('click', function(){
				newValue = $('#chartName').val();
				
				if(newValue == $('#PBchartNameHolder').text()){
					PicBoard.getTranslations(['lang_193_sameNameAlert'], function(data){
						alert(data.payload.lang_193_sameNameAlert);
					});
				} else {
					// Chart name is different. Send request to the server.
					$('#chartIDHolder').val(chartID);
					$.post(PicBoard.baseURL + "rsrc.php?req=duplicateChart", $('form#duplicateForm').serialize(), function(data){
						if(data.statusCode = 200){
							window.location = 'chart?id=' + data.chartID;
						} else {
							alert(data.message);
						}
					},
					'json');
				}
			});
		});
	});
	
	ieOverflowFixer();
}

function ieOverflowFixer(){
	// Check to see if the working area is zoomable.
	if( parseInt($('#cellHolder').width()) > parseInt($('#chartHolder').width()) || parseInt($('#cellHolder').height()) > parseInt($('#chartHolder').height()) ) {
		if($.browser.msie == true) {
			$('#chartHolder').css({'overflow': 'scroll' });
			$('#chart').css('overflow', 'hidden');
		}
	} else {
		if($.browser.msie == true) {
			$('#chartHolder').css({'overflow': 'scroll', 'width': parseInt($('#chartHolder').width())+10 + "px" });
			$('#chart').css('overflow', 'hidden');
		}
	}
}

PicBoard.addLoadEvent( "renderInformation()" );